<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>JMW-|-小姐姐</title>
<script type="text/javascript">
   if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
    //    window.location.href = "index.html";
    }else{
        window.location.href = "pc.html";
    }
</script>
<style type="text/css">
*{
    margin:0px; 
    padding:0px;
    touch-action: pan-y;
    text-align: center;
}
.app{
    width: 100%; 
    height:100%; 
    position: absolute; 
    top:0px; 
    right:0px; 
    bottom: 0px; 
    left:0px; 
    overflow: hidden;
    background-color: #ffffff;
}

#player{
    width: 100%;
    height: 100%;
    object-fit: cover; 
    object-position: center center;
    z-index: 100;
}
</style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?86194243b3d0dc98474adb8d6755d003";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<body>
    <div class="app">
        <video id="player" src="demo.mp4" preload autoplay webkit-playsinline='true' playsinline='true' x-webkit-airplay='true' x5-video-player-type='h5' x5-video-player-fullscreen='true' x5-video-ignore-metadata='true' controlslist="nodownload" poster="bg.jpg"></video>
    </div>
    
    <span style="position:absolute;top:5px;left:10px;color:#fff;font-size:10px;">右/上滑切换下一个</span>
    <span style="position:absolute;top:20px;left:10px;color:#fff;font-size:10px;">单击播放/暂停</span>
    <span style="position:absolute;top:35px;left:10px;color:#fff;font-size:10px;">双击进入全屏</span>

    <div id="buttons" style="position:absolute;bottom:150px;right:10px;">
        <button id="bth" style="border-radius:20px;width:32px;height:32px;">循环</button>
    </div>

    <span style="position:absolute;top:5px;right:5px;color:#fff;font-size:10px;">当前视频库:[<span style="color: #FF4040;">*****</span>]</span>
    <span style="position:absolute;top:25px;right:10px;color:#fff;font-size:10px;">URL-ID:[<span style="color: #4682B4;">*****</span>]</span>

    <span style="position:absolute;bottom:10px;left:10px;color:#fff;font-size:9px;">本程序仅作研究学习演示，视频采集自网络<br>原作者拍摄创作不易，请勿下载传播<br><strong style="color:red;font-size:8px;">如您想要删除某个视频链接，请携带URL-ID联系我们</strong></span>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var auto = false;
    var player = document.getElementById("player");
 
    $("#bth").on("click", function(){
        auto = !auto;
        this.innerText = (auto ? '连播' : '循环');
    });

    player.addEventListener('ended', function () {
        console.log("播放结束");
        if (auto == false) {
            player.play();
        } else {
            players();
        }
    }, false);

    var touchtime = new Date().getTime();
    $("#player").on("click", function(){
        if( new Date().getTime() - touchtime < 500 ){
            console.log("dblclick");
            FullScreen();
        }else{
            touchtime = new Date().getTime();
            console.log("click");
            if (player.paused) {
                player.play();
            } else {
                player.pause();
            }
        }
    });
});

function players() {
    $.get("get.php",function(data,status){
        if (status==status) {
            console.log("成功获取数据！");
            player.src = data;
            player.play();
        } else {
            console.log("失败，重新发起请求！");
            players();
        }
    });
}

//进入全屏
function FullScreen() {
    if (player .requestFullscreen) {
        player .requestFullscreen();
        player.play();
    } else if (player .mozRequestFullScreen) {
        player .mozRequestFullScreen();
        player.play();
    } else if (player .webkitRequestFullScreen) {
        player .webkitRequestFullScreen();
        player.play();
    }
}
</script>
<script>
var startx, starty;
//获得角度
function getAngle(angx, angy) {
    return Math.atan2(angy, angx) * 180 / Math.PI;
};

//根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动
function getDirection(startx, starty, endx, endy) {
    var angx = endx - startx;
    var angy = endy - starty;
    var result = 0;

    //如果滑动距离太短
    if (Math.abs(angx) < 2 && Math.abs(angy) < 2) {
        return result;
    }

    var angle = getAngle(angx, angy);
    if (angle >= -135 && angle <= -45) {
        result = 1;
    } else if (angle > 45 && angle < 135) {
        result = 2;
    } else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
        result = 3;
    } else if (angle >= -45 && angle <= 45) {
        result = 4;
    }

    return result;
}
//手指接触屏幕
document.addEventListener("touchstart", function(e){
    startx = e.touches[0].pageX;
    starty = e.touches[0].pageY;
}, false);
//手指离开屏幕
document.addEventListener("touchend", function(e) {
    var endx, endy;
    endx = e.changedTouches[0].pageX;
    endy = e.changedTouches[0].pageY;
    var direction = getDirection(startx, starty, endx, endy);
    switch (direction) {
        case 1:
            console.log("向上！");
            players();
            break;
        case 3:
            console.log("向左！");
            players();
            break;
    }
}, false);
</script>
</html>